﻿var formname = "";
//获取待办事宜数量
function GetTaskCount()
{
    $.post('Proc/GetData.ashx', { TYPE: "GetTaskCount", PARA: "" }, function (data)
    {
        if (data == "@@N*L@@")
        {
            window.location.href = "MobiLogin.htm";
        }
        else
        {
            $.ui.updateBadge("#litaskcount", data);
        }
    });
   
}

function unload()
{
    $.post('Proc/GetData.ashx', { TYPE: "UnLoad", PARA: "" }, function (data)
    {
          window.location.href = "MobiLogin.htm";
    });
    
}

function LoadDaiban(str)
{
    jq.ui.showMask("正在加载...");
    var formnames = "";
    if (str == 0) {
        formnames = formname;
    }
    else {
        formname = "";
    }
    $.post('Proc/GetData.ashx', { TYPE: "GetTask", PARA: "0︾20" + "︾" + formnames }, function (data) {
        $($("#webchildid").siblings()).remove();
        document.getElementById("daibanyeshu").value = 1;
        $("#webchildid").parent().get().innerHTML += CreateTaskHtml(data, 0);
        //document.getElementById("webslider").getElementsByTagName("div").item(0).innerHTML+=CreateTaskHtml(data);
        $.ui.loadContent('webslider', false, false, 'slide');
    });
    jq.ui.hideMask(); 
}

function freshpage()
{
    var num = document.getElementById("daibanyeshu");
    var formnames = formname;
    $.post('Proc/GetData.ashx', { TYPE: "GetTask", PARA: num.value + "︾20" + "︾" + formnames }, function (data)
    {
        $("#webchildid").parent().get().innerHTML += CreateTaskHtml(data, parseInt(num.value, 10));
        //document.getElementById("webslider").getElementsByTagName("div").item(0).innerHTML += CreateTaskHtml(data);
        num.value = parseInt(num.value, 10) + 1;
    });
    
}

//../Extend/AutoLoadForm.aspx?entity=bpm_jiabanshenqing&amp;action=Select&amp;formid=b7e510f0-a2ef-8a0a-f8e4-1c4cbe6c86bd&amp;id=23ed6341-f0d7-445e-8551-4e82eca039b0&amp;workflowid=e71b7349-5697-4516-89f1-883c49051ad5&amp;worktaskid=b96b3f07-fbac-44e8-84d0-ea6f8517a4a7&amp;statues=1
//展示待办事宜
function CreateTaskHtml(data,num)
{
    var obj = $.parseJSON(data);
    var str = "";
    for (var i = 0, len = obj.length; i < len; i++)
    {
        if (obj[i].FormType === "Html")
        {
            str += "<div ><h2><a href='MAutoForm.aspx?title=" + obj[i].FlowInstanceCaption + "&OperatorInstanceId=" + obj[i].operatorInstanceId + "' title='" + obj[i].FlowInstanceCaption + "' target='_blank' class='a-title' data-persist-ajax='true' data-refresh-ajax='true' data-pull-scroller='true' >" + subCaption(obj[i].FlowInstanceCaption) + "<span >" + parseInt(parseInt(num * 20) + parseInt(i) + 1) + "</span></a></h2>"
             + "<p>任务名：" + obj[i].TaskInstanceCaption + "<br />提交人：" + obj[i].pOperatedDes + "</p></div>";
        }
        else if (obj[i].FormType === "Page"||obj[i].FormType === "URL")
        {
            str += "<div ><h2><a href='../Crm/BasePages/WorkTaskCtrlMobilePage.aspx?title=" + obj[i].FlowInstanceCaption + "&OperatorInstanceId=" + obj[i].operatorInstanceId + "' target='_blank'  class='a-title'>" + subCaption(obj[i].FlowInstanceCaption) + "<span >" + parseInt(parseInt(num * 20) + parseInt(i) + 1) + "</span></a></h2>"
                            + "<p>任务名：" + obj[i].TaskInstanceCaption + "<br />提交人：" + obj[i].pOperatedDes + "</p></div>";
        }
        else
        {
            str += "<div ><h2><a href='javascript:alert(\"未指定跳转页！\"); '  class='a-title'>" + subCaption(obj[i].FlowInstanceCaption) + "<span >" + parseInt(parseInt(num * 20) + parseInt(i) + 1) + "</span></a></h2>"
                + "<p>任务名：" + obj[i].TaskInstanceCaption + "<br />提交人：" + obj[i].pOperatedDes + "</p></div>";
            
        }
    }
    return str;
}

function subCaption(str)
{
    if (str.length < 15)
        return str + "  >"
    else
        return str.substr(0,15)+".. >";

}

function SelectDetp() {
//    var sel = document.getElementsByName("SelectForDept")[0];
//    var selvalue = sel.options[sel.options.selectedIndex].value//你要的值
    var dept = $("#SelectForDept").val();
    var name = $("#selectname").val();
    alert(dept);
    jq.post("Proc/GetData.ashx", { TYPE: "GetUser", PARA: dept + "," + name }, function (data)
    {
        jq("#testform").html(CreateTaskHtmltest(data));
    });
    //var ss = '[{"EmpID":"d8c1ee42-205a-422d-a213-3c4ee863c7ef","UserID":"22dca01a-4d31-4430-9202-6f2144793c42","Name":"黄庆辉","DeptID":"5872f096-1190-4ddf-88d8-5b5b0768e407","DeptName":"销售部","EmpCode":"ZB02882","LoginName":"huangqinghui"},{"EmpID":"d8c1ee42-205a-422d-a213-3c4ee863c7ef","UserID":"22dca01a-4d31-4430-9202-6f2144793c42","Name":"周耀兵","DeptID":"5872f096-1190-4ddf-88d8-5b5b0768e407","DeptName":"IT部","EmpCode":"ZB02282","LoginName":"zhouyaobing"}]';
    //jq("#testform").html(CreateTaskHtmltest(ss));
}

function CreateTaskHtmltest(ud)
{
    var obj = $.parseJSON(ud);
    var str = "";
    for (var i = 0, len = obj.length; i < len; i++) {
        //str += "<ul style='float:left;'><li><input type='checkbox' EmpCode=" + obj[i].EmpCode + " EmpName=" + obj[i].Name + " name='dns_area'  value='" + obj[i].LoginName + "' /></li><li>" + obj[i].EmpCode + "</li><li>" + obj[i].Name + "</li><li>" + obj[i].DeptName + "</li> </ul>";
        str += "<fieldset><input type='checkbox' EmpCode=" + obj[i].EmpCode + " EmpName=" + obj[i].Name + " name='dns_area'  value='" + obj[i].LoginName + "' /> " + obj[i].EmpCode + "--" + obj[i].Name + "--" + obj[i].DeptName + " </fieldset>";
    }
    return str;
}
function showPopup3() {
    $("#jQUi").popup({ title: "Login",
        message: "表单名称: <input type='text' id='formnames' value='"+formname+"' class='jq-ui-forms'>",
        cancelText: "取消",
        cancelCallback: function () { },
        doneText: "查询",
        doneCallback: function () {
            formname = $("#formnames").val();
            LoadDaiban(0);
        },
        cancelOnly: false
    }
                );
}